import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provide/provide.dart';
import '../provide/person.dart';
import 'package:fluttertoast/fluttertoast.dart';
import './history_page.dart';

class MemberPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
     appBar: AppBar(
       title: Text('会员中心'),
     ),
     body:ListView(
       children: <Widget>[
         _topHeader(context),
         _orderTitle(),
         _deleteTitle(),
         _orderType(context),
         _actionList(context)
       ],
     ) ,
   );
  }

  Widget _topHeader(context){

    return Container(
      width: ScreenUtil().setWidth(750),
      padding: EdgeInsets.all(20),
      color: Theme.of(context).primaryColor,
      child: Column(
        children: <Widget>[
          Container(
            margin: EdgeInsets.only(top: 10),
            child: Image.asset('images/touxiang.png',width:200)
          ),
          Container(
            margin: EdgeInsets.only(top: 10),
            child: Provide<PersonnalProvider>(
              builder: (context,child,val){
                return Text(
                  val.username,
                  style: TextStyle(
                    fontSize: ScreenUtil().setSp(36),
                    color:Colors.white,
                  ),
                );
              },
            )
          )
        ],
      ),
    );
  }

  //我的订单顶部
  Widget _orderTitle(){

    return Container(
      margin: EdgeInsets.only(top:10),
      decoration: BoxDecoration(
        color: Colors.white,
        border: Border(
          bottom:BorderSide(width: 1,color:Colors.black12)
        )
      ),
      child: Provide<PersonnalProvider>(
        builder: (context,child,val){
          return ListTile(
            onTap: (){
              if(val.username=='游客'){
                Fluttertoast.showToast(
                  msg: '请先登录',
                  toastLength: Toast.LENGTH_SHORT,
                  gravity: ToastGravity.BOTTOM,
                  timeInSecForIos: 1,
                  backgroundColor: Theme.of(context).primaryColor,
                  textColor: Colors.white,
                  fontSize: 16.0
                );
                return;
              }
              // 查找历史订单
              Navigator.push(context,MaterialPageRoute(
                builder: (context){
                  return History();
                }
              ));
            },
            leading: Icon(Icons.list),
            title:Text('我的订单'),
            trailing: Icon(Icons.arrow_right),
          );
        },
      )
    );
  }

  //我的订单顶部
  Widget _deleteTitle(){

    return Container(
      margin: EdgeInsets.only(top:10),
      decoration: BoxDecoration(
        color: Colors.white,
        border: Border(
          bottom:BorderSide(width: 1,color:Colors.black12)
        )
      ),
      child: Provide<PersonnalProvider>(
        builder: (context,child,val){
          return ListTile(
            onTap: (){
              if(val.username=='游客'){
                Fluttertoast.showToast(
                  msg: '请先登录',
                  toastLength: Toast.LENGTH_SHORT,
                  gravity: ToastGravity.BOTTOM,
                  timeInSecForIos: 1,
                  backgroundColor: Theme.of(context).primaryColor,
                  textColor: Colors.white,
                  fontSize: 16.0
                );
                return;
              }
              // 删除历史订单
              Provide.value<PersonnalProvider>(context).deleteCart(context);
            },
            leading: Icon(Icons.list),
            title:Text('删除订单'),
            trailing: Icon(Icons.arrow_right),
          );
        },
      )
    );
  }

  Widget _orderType(context){
    return InkWell(
      onTap: (){
        Fluttertoast.showToast(
          msg: '没写别点了',
          toastLength: Toast.LENGTH_SHORT,
          gravity: ToastGravity.BOTTOM,
          timeInSecForIos: 1,
          backgroundColor: Theme.of(context).primaryColor,
          textColor: Colors.white,
          fontSize: 16.0
        );
      },
      child: Container(
        margin: EdgeInsets.only(top:5),
        width: ScreenUtil().setWidth(750),
        height: ScreenUtil().setHeight(150),
        padding: EdgeInsets.only(top:20),
        color: Colors.white,
        child: Row(
          children: <Widget>[
            Container(
              width: ScreenUtil().setWidth(187),
              child: Column(
                children: <Widget>[
                  Icon(
                    Icons.party_mode,
                    size: 30,
                  ),
                  Text('待付款'),
                ],
              ),
            ),
            //-----------------
            Container(
              width: ScreenUtil().setWidth(187),
              child: Column(
                children: <Widget>[
                  Icon(
                    Icons.query_builder,
                    size: 30,
                  ),
                  Text('待发货'),
                ],
              ),
            ),
            //-----------------
            Container(
              width: ScreenUtil().setWidth(187),
              child: Column(
                children: <Widget>[
                  Icon(
                    Icons.directions_car,
                    size: 30,
                  ),
                  Text('待收货'),
                ],
              ),
            ),
            Container(
              width: ScreenUtil().setWidth(187),
              child: Column(
                children: <Widget>[
                  Icon(
                    Icons.content_paste,
                    size: 30,
                  ),
                  Text('待评价'),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _myListTile(String title){

    return Container(
       decoration: BoxDecoration(
        color: Colors.white,
        border: Border(
          bottom:BorderSide(width: 1,color:Colors.black12)
        )
      ),
      child: ListTile(
        leading: Icon(Icons.blur_circular),
        title: Text(title),
        trailing: Icon(Icons.arrow_right),
      ),
    );
  }

  Widget _actionList(context){
    return InkWell(
      onTap: (){
        Fluttertoast.showToast(
          msg: '没写别点了',
          toastLength: Toast.LENGTH_SHORT,
          gravity: ToastGravity.BOTTOM,
          timeInSecForIos: 1,
          backgroundColor: Theme.of(context).primaryColor,
          textColor: Colors.white,
          fontSize: 16.0
        );
      },
      child: Container(
        margin: EdgeInsets.only(top: 10),
        child: Column(
          children: <Widget>[
              _myListTile('领取优惠券'),
              _myListTile('已领取优惠券'),
              _myListTile('地址管理'),
              _myListTile('客服电话'),
              _myListTile('关于我们'),
          ],
        ),
      ),
    );
  }
}